package day07;

import java.util.Random;
import java.util.Scanner;

public class Practice02 {
    public static void main(String[] args) {
        /**
         * 需求:
         * <<主持人大赛>>有6名评委给选手打分，要求分数范围为0到100之间的整数。
         * 选手的最后得分为：去掉最高分、最低分后的4个评委的平均分
         */

        double[] scores = enterData(6);
        double avg = calAvg(scores);
        System.out.println("平均分为:"+avg);




        /*
     需求：
     机票价格按照淡季旺季、头等舱、商务舱和经济舱收费，
     输入机票原价、月份和头等舱、商务舱或经济舱，
     其中旺季（5-10月）头等舱9折，商务舱85折，经济舱8折，
     淡季（11月到来年4月）头等舱7折，商务舱65折，经济舱6折，
     最终输出机票价格
      */

        /*
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入机票原价:");
        double price = scan.nextDouble();
        System.out.println("请输入月份:");
        int month = scan.nextInt();
        System.out.println("请选择舱位: 1.头等舱 2.商务舱 3.经济舱");
        int type = scan.nextInt();

        double finalPrice = calAirPrice(price,month,type);
        if(finalPrice!=-1){
            System.out.println("机票的最终价格为:"+finalPrice);
        }

         */




        /**
         * 猜数字小游戏
         * 训练目标: while(true)自造死循环
         */

        /*
                Scanner scan = new Scanner(System.in);
                int num = (int)(Math.random()*1000+1); //1到1000
                while(true){
                    System.out.println("猜吧!");
                    int guess = scan.nextInt();
                    if(guess>num){
                        System.out.println("猜大了");
                    }else if(guess<num){
                        System.out.println("猜小了");
                    }else{
                        System.out.println("恭喜你猜对了");
                        break;
                    }
                }
            }

         */



        /**
         * 需求:----------常见面试题
         *   找到2到100之间的所有素数(质数)
         *   素数:除了1和它本身外，不能被其它任何自然数整数的数
         */

        /*
        for(int i=2;i<=100;i++){
            boolean a=true;
            for(int j=2;j<=i/2;j++){
                if(i%j==0){
                    a=false;
                    break;
                }
            }
            if(a){
                System.out.print(i+" ");
            }
        }

         */

       // String veriCode = generateVeriCode(6);
       // System.out.println(veriCode);

    }

    public static String generateVeriCode(int times){
        String code="";
        char[] chs = {'a','b','c','d','e','f','g','h','i','j','k',
                'l','m','n','o','p','q','r','s','t','u','v',
                'w','x','y','z','A','B','C','D','E','F','G',
                'H','I','J','K','L','M','N','O','P','Q','R',
                'S','T','U','V','W','X','Y','Z','0','1','2',
                '3','4','5','6','7','8','9','达','内'};
        Random rand=new Random();
        for(int i=0;i<times;i++) {
            int index = rand.nextInt(chs.length);
            code+=chs[index];
        }
        return code;
    }

    public static double calAirPrice(double price,int month,int type){
        double lastPrice = 0.0;

        if(month<1 || month>12){
            System.out.println("月份输入错误");
            return -1;
        }
        if(type<1 || type>3){
            System.out.println("舱位输入错误");
            return -1;
        }

        if(month>=5 && month<=10){ //旺季
            switch(type){
                case 1:
                    lastPrice = price*0.9;
                    break;
                case 2:
                    lastPrice = price*0.85;
                    break;
                case 3:
                    lastPrice = price*0.8;
                    break;
            }
        }else{ //淡季
            switch(type){
                case 1:
                    lastPrice = price*0.7;
                    break;
                case 2:
                    lastPrice = price*0.65;
                    break;
                case 3:
                    lastPrice = price*0.6;
                    break;
            }
        }

        return lastPrice;
    }

    public static double[] enterData(int num) {
        Scanner scan = new Scanner(System.in);
        double[] scores = new double[num];
        for (int i = 0; i < scores.length; i++) {
            System.out.println("请录入第" + (i + 1) + "个评委的分数:");
            scores[i] = scan.nextDouble();
        }
        return scores;
    }

    public static double calTotal(double[] scores) {
        double total = 0.0;
        double max = scores[0];
        double min = scores[0];
        for (int i = 0; i < scores.length; i++) {
            if (scores[i] > max) {
                max = scores[i];
            }
            if (scores[i] < min) {
                min = scores[i];
            }
            total += scores[i];
        }
        return total - max - min;
    }

    public static double calAvg(double[] scores) {
        double total = calTotal(scores);
        double avg = total / (scores.length - 2);
        return avg;
    }
    }
